package com.jinmdz.fmis.dao.admin.dao.provider;

import com.jinmdz.fmis.dao.base.BaseProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 系统菜单Provider
 *
 * @author LiCongLu
 * @date 2020-03-18 11:36
 */
public class SystemMenuProvider extends BaseProvider {

    /**
     * 查询系统菜单列表
     *
     * @param businessSystemId 业务系统主键
     * @return
     * @author LiCongLu
     * @date 2020-03-18 15:29
     */
    public String listSystemMenuListByBusinessSystemId(@Param("businessSystemId") Integer businessSystemId) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" business_system_menu.id,business_system_id,parent_id,menu_name,menu_route,menu_redirect_route,menu_icon ");
                builder.append(" ,business_system_menu.disable_state,business_system_menu.sort,business_system_menu.remark,business_system_menu.version");
                builder.append(" ,business_system.system_name as business_system_name");
                SELECT(builder.toString());
                FROM(" business_system_menu ");
                JOIN(" business_system on business_system.id = business_system_id ");
                WHERE(" business_system_menu.deleted = 0 and business_system.deleted = 0 ");
                WHERE(" business_system_menu.business_system_id = #{businessSystemId}");
                ORDER_BY(" business_system_menu.sort ");
            }
        }.toString();
    }

    /**
     * 按照主键获取系统菜单信息
     *
     * @param id 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-18 15:29
     */
    public String getSystemMenuEditById(@Param("id") Integer id) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" business_system_menu.id,business_system_id,parent_id,menu_name,menu_route,menu_redirect_route,menu_icon ");
                builder.append(" ,business_system_menu.disable_state,business_system_menu.sort,business_system_menu.remark,business_system_menu.version");
                builder.append(" ,business_system.system_name as business_system_name");
                SELECT(builder.toString());
                FROM(" business_system_menu ");
                JOIN(" business_system on business_system.id = business_system_id ");
                WHERE(" business_system_menu.deleted = 0 and business_system.deleted = 0 ");
                WHERE(" business_system_menu.id = #{id}");
                ORDER_BY(" business_system_menu.id limit 1 ");
            }
        }.toString();
    }
}
